﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Text;

namespace DH.Web.MVC
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); /* 支持中文 */

            BuildWebHost(args).Run();
        }

        //public static IWebHost BuildWebHost(string[] args) =>
        //    WebHost.CreateDefaultBuilder(args)
        //        .UseStartup<Startup>()
        //        .Build();

        

        public static IWebHost BuildWebHost(string[] args)
        {
            var config = new ConfigurationBuilder()
                 .SetBasePath(Directory.GetCurrentDirectory())
                 .AddJsonFile("config/hosting.json", optional: true)
                 .Build();
            var host = new WebHostBuilder()
             .UseKestrel()
             .UseUrls("http://*:5000")//即可实现通过IP访问程序。
             .UseConfiguration(config)
             .UseContentRoot(Directory.GetCurrentDirectory())
             .UseIISIntegration()
             .UseApplicationInsights()
             .UseStartup<Startup>()
             .Build();

            return host;
        }

           
    }
}
